#include "SDLToolBox.h"

#ifndef IO_HEADER
    #include <iostream>
    #define IO_HEADER
#endif

void SDLToolBox::InitSDL(int Width, int Height)
{
    int result = SDL_Init(SDL_INIT_VIDEO);
    if(result < 0) std::cout << "Erreur d'initialisation de SDL" << std::endl;

    atexit(SDL_Quit);

    Screen = SDL_SetVideoMode(Width, Height, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
    if(!Screen) std::cout << "Erreur d'initialisation de SDL" << std::endl;
}

void SDLToolBox::CleanUpSDL()
{
    SDL_Quit();
}

void SDLToolBox::Clear(Uint8 R, Uint8 G, Uint8 B)
{
    int result = SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format, R, G, B));
    if(result < 0) std::cout << "Erreur à l'effacement" << std::endl;
}

void SDLToolBox::Render()
{
    int result = SDL_Flip(Screen);
    if(result < 0) std::cout << "Erreur lors du rendu (flip)" << std::endl;
}
